#include "../../lib/daytimelib.h"
#include "../clientcommon.h"

int main(int argc, char **argv) {

    if (argc != 2) err_quit("usage: a.out <IPaddres>");

    // normal code
    int sockfd, n;
    struct sockaddr_in servaddr;

    bzero(&servaddr, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_port = htons(8989);
    Inet_pton(AF_INET, argv[1], &servaddr.sin_addr);

    // service code
    char recvline[MAXLINE + 1];

    for ( ; ; ) {
        sockfd = ClientInit(AF_INET, SOCK_STREAM, 0, servaddr);
        while ((n = Read(sockfd, recvline, MAXLINE)) > 0) {
            recvline[n] = 0;
            if (fputs(recvline, stdout) == EOF) {
                err_sys("fputs error");
            }
        }
        sleep(1);
        Close(sockfd);
    }

   

    return 0;
}